package com.ftm.dao.impl;

import java.util.List;

import com.ftm.dao.ItemsDao;
import com.ftm.entity.Items;
import com.ftm.entity.Orders;
import com.ftm.tools.DBTools;
import com.ftm.tools.PageData;

public class ItemsDaoImpl implements ItemsDao{
	//新增订单项 (√)
	@Override
	public boolean addItems(Items items) {
		String sql="insert into ftm_items values(null,?,?,?,?)";
		return DBTools.exUpdate(sql, items.getCount(),items.getGoodsid(),items.getOrderid(),items.getCost())>0;
	}
	//删除订单项(√)
	@Override
	public boolean delItems(int itemsid) {
		String sql="delete from ftm_items where itemsid=?";
		return DBTools.exUpdate(sql, itemsid)>0;
	}
	//修改订单项中的数量和花费(√)
	@Override
	public boolean UpItems(int count,double cost,int itemsid) {
		String sql="update ftm_items set count=? ,cost=? where itemsid=?";
		return DBTools.exUpdate(sql, count,cost,itemsid)>0;
	}
	//查看商店中的所有订单项
	@Override
	public PageData <Items> queryItemsShop(int page, int pageSize, int shopid) {
		String sql="select * from ftm_items  where goodsid in (select goodsid from ftm_goods  where shopid=1)";
		return DBTools.exQueryByPage(sql, Items.class, page, pageSize, shopid);
	}
	//商店中单一商品的订单项(√)
	@Override
	public PageData <Items> queryItemsGoods(int page, int pageSize, int goodsid) {
		String sql="select * from ftm_items  where goodsid=?";
		return DBTools.exQueryByPage(sql, Items.class, page, pageSize, goodsid);
	}
	//查看订单(一个订单下的多个订单项)(√)
	@Override
	public PageData <Items>queryItemsOrder(int page, int pageSize, int orderid) {
		String sql="select * from ftm_items  where orderid=?";
		return DBTools.exQueryByPage(sql, Items.class, page, pageSize, orderid);
	}
	//查看订单项详情(√)
	@Override
	public Items queryOneItems(int itemsid) {
		String sql="select * from ftm_items  where itemsid=?";
				
		List<Items > list =  (List<Items>) DBTools.exQuery(sql, Items.class, itemsid);
		if (list.size() == 0) {
			return null;
		}
		return list.get(0);
		
	}

}
